#include "comm.h"

int main()
{
    umask(0);
    if(mkfifo(MY_FIFO, 0666) < 0)
    {
        printf("mkfifo failed\n");
	exit(1);
    }
    int fd = open(MY_FIFO, O_RDONLY);
    if(fd < 0)
    {
	printf("open failed\n");
	exit(2);
    }
    char buffer[64];
    while(1)
    {
	buffer[0] = 0;
        ssize_t s = read(fd, buffer, 63);
 	if(s > 0)
        {
	    buffer[s] = 0;
	    if(strcmp(buffer, "ls") == 0)
	    {
	        if(fork() == 0)
		   execl("/usr/bin/ls", "ls", "-l", NULL);
	    }
	    else if(strcmp(buffer, "sl") == 0)
            {
		if(fork() == 0)
		   execl("/usr/bin/sl", "sl", NULL);
	    }
	    else
	    	printf("client say to server# %s\n", buffer);	
        }
    }  
    return 0;
}
